parameters:
  runtimeFlavor: ''
  archType: ''
  buildConfig: ''
  creator: ''
  helixQueues: ''
  osGroup: ''
  targetRid: ''
  testRunNamePrefixSuffix: ''
  testScope: 'innerloop' # innerloop | outerloop | all
  interpreter: ''
  condition: always()
  extraHelixArguments: ''
  shouldContinueOnError: false
  scenarios: ''
  SuperPmiCollect: ''
  SuperPmiCollectionType: ''
  SuperPmiCollectionName: ''

steps:
  - script: $(_msbuildCommand) $(_warnAsErrorParamHelixOverride) -restore
            $(Build.SourcesDirectory)/src/libraries/sendtohelix.proj
            /p:RuntimeFlavor=${{ parameters.runtimeFlavor }}
            /p:TargetArchitecture=${{ parameters.archType }}
            /p:TargetRuntimeIdentifier=${{ parameters.targetRid }}
            /p:Configuration=${{ parameters.buildConfig }}
            /p:TargetOS=${{ parameters.osGroup }}
            /p:MonoForceInterpreter=${{ parameters.interpreter }}
            /p:TestScope=${{ parameters.testScope }}
            /p:TestRunNamePrefixSuffix=${{ parameters.testRunNamePrefixSuffix }}
            /p:HelixBuild=$(Build.BuildNumber)
            ${{ parameters.extraHelixArguments }}
            /bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/SendToHelix.binlog
    displayName: Send to Helix
    condition: and(succeeded(), ${{ parameters.condition }})
    continueOnError: ${{ eq(parameters.shouldContinueOnError, true) }}
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken) # We need to set this env var to publish helix results to Azure Dev Ops
      _Scenarios: ${{ join(',', parameters.scenarios) }} # Pass scenarios to MSBuild as env var to avoid need of escaping comma separated list
      _SuperPmiCollect: ${{ parameters.SuperPmiCollect }}
      _SuperPmiCollectionType: ${{ parameters.SuperPmiCollectionType }}
      _SuperPmiCollectionName: ${{ parameters.SuperPmiCollectionName }}

      ${{ if eq(variables['System.TeamProject'], 'internal') }}:
        HelixAccessToken: $(HelixApiAccessToken)
        HelixTargetQueues: ${{ replace(lower(join('+', parameters.helixQueues)), '.open', '') }}
        Creator: ''
      ${{ if eq(variables['System.TeamProject'], 'public') }}:
        HelixTargetQueues: ${{ join('+', parameters.helixQueues) }}
        Creator: ${{ parameters.creator }}
